#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/input.h>
#include <unistd.h>
#include <sys/ioctl.h>

#define GPIO_TO_PIN(bank, gpio) (32 * (bank) + (gpio))

int main(int argc, char * argv)
{
        int i, n, fd;
        char num;
        int ret;
        fd = open("/dev/gpioCtl", O_RDWR);                //打开设备
        if (fd < 0)
        {
            printf("can't open /dev/gpioCtl!\n");
            exit(1);
        }
        sleep(1);
        ioctl(fd, 1, GPIO_TO_PIN(1,22));                //设置gpio1-22为输出（user:led3）
        ioctl(fd, 0, GPIO_TO_PIN(2, 1));                //设置gpio2-1 为输入（p8-18）
        while (1) 
        {
                num = 1;
                ret = write(fd,"1",GPIO_TO_PIN(1,22));
		printf("on");
                if(ret < 0)
                {
                        perror("write");
                        return -1;
                }
                sleep(1);
                ret = write(fd,"0",GPIO_TO_PIN(1,22));
		printf("off");
                if(ret < 0)
                {
                    perror("write");
                    return -1;
		}
		sleep(1);
	}
}
